sts = -1 # Child not completed yet
- def __init__(self, cmd, capturestderr=False, bufsize=-1, passfd=()):
+ def __init__(self, cmd, capturestderr=False, bufsize=-1, passfd=(), env=None):
"""The parameter 'cmd' is the shell command to execute in a
sub-process. The 'capturestderr' flag, if true, specifies that
the object should capture standard error output of the child process.
pass
try:
os.execvp(cmd[0], cmd)
+ if env is None:
+ os.execvp(cmd[0], cmd)
+ else:
+ os.execvpe(cmd[0], cmd, env)
finally:
os._exit(127)
return self.sts
-def xpopen2(cmd, bufsize=-1, mode='t', passfd=[]):
+def xpopen2(cmd, bufsize=-1, mode='t', passfd=[], env=None):
"""Execute the shell command 'cmd' in a sub-process. If 'bufsize' is
specified, it sets the buffer size for the I/O pipes. The file objects
(child_stdout, child_stdin) are returned."""
- inst = xPopen3(cmd, False, bufsize, passfd)
+ inst = xPopen3(cmd, False, bufsize, passfd, env)
return inst.fromchild, inst.tochild
-def xpopen3(cmd, bufsize=-1, mode='t', passfd=[]):
+def xpopen3(cmd, bufsize=-1, mode='t', passfd=[], env=None):
"""Execute the shell command 'cmd' in a sub-process. If 'bufsize' is
specified, it sets the buffer size for the I/O pipes. The file objects
(child_stdout, child_stdin, child_stderr) are returned."""
- inst = xPopen3(cmd, True, bufsize, passfd)
+ inst = xPopen3(cmd, True, bufsize, passfd, env)
return inst.fromchild, inst.tochild, inst.childerr
+
+def call(*popenargs, **kwargs):
+ """Run command with arguments. Wait for command to complete, then
+ return the status.
+
+ The arguments are the same as for the xPopen3 constructor. Example:
+
+ status = call("ls -l")
+ """
+ return xPopen3(*popenargs, **kwargs).wait()
from xen.xend import XendOptions
from xen.xend.XendLogging import log
from xen.xend.XendError import VmError
-from xen.util import dictio, xsconstants, auxbin
+from xen.util import dictio, xsconstants, auxbin, xpopen
from xen.xend.XendConstants import *
#global directories and tools for security management
log.info("Running resource label change script %s: %s" %
(script, parms))
parms.update(os.environ)
- os.spawnve(os.P_WAIT, script[0], script, parms)
+ xpopen.call(" ".join(script, params))
else:
log.info("No script given for relabeling of resources.")
if not __script_runner:
# Copyright (c) 2005, XenSource Ltd.
import string, re
-import popen2
from xen.xend.server.blkif import BlkifController
from xen.xend.XendLogging import log
+from xen.util.xpopen import xPopen3
phantomDev = 0;
phantomId = 0;
def doexec(args, inputtext=None):
"""Execute a subprocess, then return its return code, stdout and stderr"""
- proc = popen2.Popen3(args, True)
+ proc = xPopen3(args, True)
if inputtext != None:
proc.tochild.write(inputtext)
stdout = proc.fromchild